import logging
import logging.handlers

from config import BASE_DIR


def init_log_config(filename, when='midnight', interval=1, backup_count=7):
    logger = logging.getLogger()
    logger.setLevel(logging.INFO)

    st = logging.StreamHandler()
    fh = logging.handlers.TimedRotatingFileHandler(filename=filename, when=when, interval=interval,
                                                   backupCount=backup_count)

    fmt = "%(asctime)s - %(funcName)s - %(levelname)s - %(message)s]"
    formatter = logging.Formatter(fmt)

    st.setFormatter(formatter)
    fh.setFormatter(formatter)

    logger.addHandler(st)
    logger.addHandler(fh)


if __name__ == '__main__':
    def my_logger():
        init_log_config(BASE_DIR + 'my_log.log')
        logging.info("This is a log info")


    my_logger()
# 2025-01-06 18:06:49,310 - my_logger - INFO - This is a log info]
